/*                                    _
 *   ___ _ __ ___ _ __ ___   ___   __| |
 *  / __| '__/ __| '_ ` _ \ / _ \ / _` |
 *  \__ \ |  \__ \ | | | | | (_) | (_| |
 *  |___/_|  |___/_| |_| |_|\___/ \__,_|                                  
 *
 *              _ _     _  _|
 *             | (_)|_|| |(_|
 *       __|_ _ _|_ _   |_  _ | _  _  _
 *      _\ | (_| | (/_  | |(/_||_)(/_| 
 *                            |               
 ******************************************
 ******************************************
 ******************************************
 *  _    |_ |. _   |`    _  __|_. _  _  _
 * |_)|_||_)||(_  ~|~|_|| |(_ | |(_)| |_\
 * |                                     
 *		// Is this the first round (or earlier?)
 *		RoundStatus_IsFirstRound()
 *
 *		// Is this the second round (or later?)
 *		RoundStatus_IsSecondRound()
 *
 *		// Is a Finale going on currently?
 *		RoundStatus_IsFinale()
 *
 ******************************************
 ******************************************
 ******************************************
 * . _ _  _ | _  _ _  _  _ _|_ _ _|_. _  _ 
 * || | ||_)|(/_| | |(/_| | | (_| | |(_)| |
 *       |                                 
 *		The round_start/round_end events in L4D(2) are
 *		far trickier than they need to be. It is possible to get a 
 *		round_start before an OnMapStart, or more than one round_start,
 *		more than one round_end, etc.
 *
 *		So to avoid worrying about all that this tried-and-tested
 *		round counter will worry about whether its in first or second
 *		round.
 *	
 *		The code is very straight-forward, but don't let that fool you,
 *		adding in other event checks could very well break it.
 */
 
static bool:isSecondRound; //second round or later (esp. in scavenge)
static bool:isFinale;
static bool:beforeMapStart;

stock bool:RoundStatus_IsFirstRound()
{
	return !isSecondRound;
}

stock bool:RoundStatus_IsSecondRound()
{
	return isSecondRound;
}

stock bool:RoundStatus_IsFinale()
{
	return isFinale;
}

stock bool:RoundStatus_IsBeforeMapStart()
{
	return beforeMapStart;
}

RoundCounter_OnPluginStart()
{
	HookEvent("round_end", _RC_RoundEnd_Event, EventHookMode_PostNoCopy);
	HookEvent("finale_start", _RC_FinaleStart_Event, EventHookMode_PostNoCopy);
}

RoundCounter_OnMapStart()
{
	beforeMapStart = false;
}

RoundCounter_OnMapEnd()
{
	isSecondRound = false;
	beforeMapStart = true;
}

public Action:_RC_RoundEnd_Event(Handle:event, const String:name[], bool:dontBroadcast)
{
	isSecondRound = true;
	isFinale = false;
}

public Action:_RC_FinaleStart_Event(Handle:event, const String:name[], bool:dontBroadcast)
{
	isFinale = true;
}